#include <iostream>
#include <memory>
using namespace std;

class A
{
public:
    A(int i)
    {
        cout<<"A()"<<endl;
        _i = new int;
        *_i = i;

    }
    ~A()
    {
        cout<<"~A()"<<endl;
        if(_i != nullptr)
        {
            delete _i;
        }
    }

    A(const A& another)
    {
        cout<<"A(const A& a)"<<endl;
        _i = new int;
        *_i = *another._i;
    }
    void dis()
    {
        cout<<"*_i = "<<*_i<<endl;
    }
    int *_i;
};

void func(auto_ptr <A> apc)
{

}

int main()
{
    // unique_ptr<A> up(new A(99));
    // up->dis();
    // unique_ptr<A> up2(up);
    // up2->dis();//这种访问会报错

    int *p = new int(100);
    // {
    //     unique_ptr<int> uqi(p);
    //     cout<<*uqi<<endl;
    // }
    unique_ptr<int> uqi2(p);
    cout<<*uqi2<<endl;//不加括号能访问到100,加括号，就析构，指针变成nullptr

    unique_ptr<int> uqi3(std::move(p));
    cout<<*uqi3<<endl;


    return 0;
}
